<template>
	<view class="content" v-if="show==1">
		<view class="news4">
			<mp-html :content="news.content" />
		</view>
	</view>
</template>

<script>
	var app=getApp();
	import mpHtml from '@/components/mp-html/mp-html'
	export default {
		components: {
		 mpHtml
		},
		data() {
			return {
				id:0,
				show:0,
				news:[]
			}
		},
		onLoad(op) {
			if(app.isBlank(op.id)==true){
				app.error_msg("缺少参数");
			}
			this.id=op.id;
			this.getdata();
		},
		methods: {
			getdata(){
				var that=this;
				uni.showLoading({
				    title: '数据加载中'
				});
				uni.request({
				    url: app.globalData.url+"index/danye",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {id:that.id},
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code!=1){
							app.error_msg(res.data.msg);
						}
						uni.setNavigationBarTitle({
						    title: res.data.data.news.title
						});
						that.news=res.data.data.news
						that.show=1;
				    }
				});
			}
		},
		filters: {
		formatRichText(html) { //控制小程序中图片大小
			let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
				match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
				match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
				match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
				return match;
			});
			newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
				match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
				return match;
			});
			newContent = newContent.replace(/<br[^>]*\/>/gi, '');
			newContent = newContent.replace(/\<img/gi,
				'<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
			return newContent;
		}
		}
	}
</script>

<style>
	.news4{width:94%;padding: 10px 3%;}
	.news3{width:100%;line-height: 25px;font-size: 0.8rem;color:#999;margin-top: 5px;}
	.news2{width:100%;line-height: 25px;font-size: 1rem;font-weight: 700;text-align: center;}
	.news{width:94%;padding:0px 3%;margin-top: 10px;}
</style>
